﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using QLTV.Public;
using System.Data.SqlClient;

namespace QLTV.DAL
{
    public class TheLoaiDAL
    {
        ConnectionData connect;

        public DataTable LoadTL_CoTenTL()
        {
            try
            {
                connect = new ConnectionData();
                return connect.GetData("THELOAI_LoadDuLieuCoTenTL");

            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public DataTable TimTheoTen(TheLoaiDTO tlDTO)
        {
            try
            {
                connect = new ConnectionData();
                int Nparamater = 1;
                string[] name = new string[Nparamater];
                object[] value = new object[Nparamater];
                name[0] = "@search";
                value[0] = tlDTO.TenTL;                             
                return connect.GetData("TheLoai_TimTheoTen", name, value, Nparamater);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public DataTable TheLoai_GetByLast()
        {
            try
            {
                connect = new ConnectionData();
                return connect.GetData("TheLoai_GetByLast");
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public DataTable TheLoai_LoadDuLieuCotMaTL(TheLoaiDTO tlDTO)
        {
            try
            {
                connect = new ConnectionData();
                int Nparamater = 1;
                string[] name = new string[Nparamater];
                object[] value = new object[Nparamater];
                name[0] = "@matl";
                value[0] = tlDTO.MaTL;
                return connect.GetData("TheLoai_LoadDuLieuCotMaTL", name, value, Nparamater);
            }
            catch(SqlException ex)
            {
                throw ex;
            }
        }
        public DataTable TheLoai_LoadTheLoai()
        {
            try
            {
                connect = new ConnectionData();
                return connect.GetData("TheLoai_LoadDuLieu");
            }
            catch (SqlException ex)
            {
                throw ex;
         
            }
        }
        public int nhapTheLoai(TheLoaiDTO tlDTO)
        {
            try
            {
                connect = new ConnectionData();
                int Nparamater = 2;
                string[] name = new string[Nparamater];
                object[] value = new object[Nparamater];
                name[0] = "@matl";
                value[0] = tlDTO.MaTL;
                name[1] = "@tentl";
                value[1] = tlDTO.TenTL;

                return connect.UpdateData("TheLoai_InsertUpdate", name, value, Nparamater);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public int TheLoai_Xoa(TheLoaiDTO tlDTO)
        {
            try
            {
                connect = new ConnectionData();
                int Nparamater = 1;
                string[] name = new string[Nparamater];
                object[] values = new object[Nparamater];
                name[0] = "@MaTL";
                values[0] = tlDTO.MaTL;
                return connect.UpdateData("TheLoai_Xoa", name, values, Nparamater);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
    }
}
